package cn.cdzdjd.handler;

import java.util.Date;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

import cn.cdzdjd.util.UserHolder;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		// 自定义创建时间、创建者的填充逻辑
		this.strictInsertFill(metaObject, "createDate", Date.class, new Date());
		this.strictInsertFill(metaObject, "createBy", Long.class, getCurrentUserId());
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		// 自定义更新时间、更新者的填充逻辑
		this.strictUpdateFill(metaObject, "updateDate", Date.class, new Date());
		this.strictUpdateFill(metaObject, "updateBy", Long.class, getCurrentUserId());
	}

	private Long getCurrentUserId() {
		// 获取当前用户ID的逻辑，根据实际情况实现
				// 例如从Security上下文中获取
		return UserHolder.getHolder();
	}
}
